#coding:utf-8
from lovewith.account.models import MtUserWeddingData


#婚礼信息
class WeddingApi:
    def __init__(self):
        pass

    @staticmethod
    def check_data(user_id):
        filter_data = MtUserWeddingData.objects.filter(user_id=int(user_id))
        if filter_data.exists():
            return filter_data[0]
        else:
            return None

    #更新
    def update(self, **kwargs):
        wedding_data = self.check_data(kwargs['user'].id)
        if wedding_data:
            for key, value in kwargs.iteritems():
                setattr(wedding_data, key, value)
            wedding_data.save()

            return wedding_data.id
        else:
            new_wedding = MtUserWeddingData(**kwargs)
            new_wedding.save()

            return new_wedding.id

